#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
SqlServer连接工具类
@author Created by Yani on 2019/02/28
"""
import pymssql


class DBUtils:

    def __init__(self, host, user, pwd, db):
        self.host = host
        self.user = user
        self.pwd = pwd
        self.db = db
        self.conn = None

    def connect(self):
        if not self.db:
            raise(NameError, "没有设置数据库信息")
        self.conn = pymssql.connect(host=self.host, user=self.user, password=self.pwd, database=self.db, charset="utf8")
        cur = self.conn.cursor()
        if not cur:
            raise(NameError, "连接数据库失败")
        else:
            return cur
